import bean.TreeNode;

public class LeetCode1448 {
    public static void main(String[] args) {

    }
    int result = 0;
    public int goodNodes(TreeNode root) {
        if (root == null){
            return result;
        }

        int largeValue = root.val;
        calculator(root, largeValue);

        return result;
    }

    void calculator(TreeNode node, int largeValue){
        if (largeValue <= node.val){
            result++;
            largeValue = node.val;
        }

        if (node.left != null){
            calculator(node.left, largeValue);
        }

        if (node.right != null){
            calculator(node.right, largeValue);
        }
    }
}
